package com.wjv.example.spbt.shiro.service;

import com.wjv.example.spbt.shiro.model.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>Title: RoleServiceImpl</p>
 *
 * @author wjv
 * @date 2021/7/5 12:00
 */
@Service
public class RoleServiceImpl {

    @Autowired
    private PermissionServiceImpl permissionService;

    private final static List<Role> roles = new ArrayList<>();

    static {
        roles.add(Role.of(1, "admin", "管理员"));
        roles.add(Role.of(2, "ops", "运维"));
        roles.add(Role.of(3, "dev", "开发"));
        roles.add(Role.of(4, "test", "测试"));
    }

    /**
     * 根据用户 获取对应的 角色
     * @param userName
     * @return
     */
    public List<Role> getRoleByUser(String userName) {
        List<Role> list = new ArrayList<>();
        Role role = roles.get(1);
        role.setPermissions(permissionService.getPermissions(1));
        list.add(role);
        return list;
    }
}
